//
//  CHJCaptureManager.h
//  CHJVideoKit
//
//  Created by jiaxuzhou on 2017/11/29.
//

#import <Foundation/Foundation.h>
#import "SenseAr.h"

/// 屏幕尺寸
typedef enum : NSUInteger {
    /// 全屏
    CHJCameraCaptureType_FullScreen,
    /// 正方形
    CHJCameraCaptureType_Square,
    /// 窄屏
    CHJCameraCaptureType_ZhaiPing,
    /// 4:5视频
    CHJCameraCaptureType_4_5
} CHJCameraCaptureType;


typedef enum : NSUInteger {
    TeXiao_Type_Face,
    TeXiao_Type_Hand,
    TeXiao_Type_Face_Hand
} TeXiao_Type;

@protocol CHJCameraDelegate <NSObject>


/**
 拍摄时间回调  时时 更新UI时间
 @param duration 时长
 */
- (void)chj_fullscreen_camera_captured_duration:(CGFloat)duration;


/**
 每有一段视频掉一次 每拍摄一段视频处理完成回调
 @param error 错误信息
 */
- (void)chj_fullscreen_camera_captured_video:(NSError *)error;

/**
 对焦完成回调
 */
- (void)chj_fullscreen_camera_did_stop_focus;

/**
 切换摄像头后的摄像头位置 更新UI
 
 @param is_front 是否是前置 YES 前置， NO 后置
 */
- (void)chj_fullscreen_camera_changed_device_position:(BOOL)is_front;

- (void)chj_fullscreen_camera_detected_face:(BOOL)face_result;

- (void)chj_fullscreen_camera_detected_hand:(BOOL)hand_result;
/// 取景器是否初始化完成
- (void)chj_fullscreen_camera_initSessionPrepared:(BOOL)isPrepared;
- (BOOL)chj_fullscreen_camera_getNetWorking;

@end

@interface CHJCaptureManager : NSObject

/**
 设置屏幕尺寸
 */
@property (nonatomic, assign) CHJCameraCaptureType captureType;
@property (nonatomic, assign) CGRect previewFrame;
@property (nonatomic, weak) id<CHJCameraDelegate> delegate;

@property (nonatomic, strong, readonly) SenseArMaterialService *serviceR;

#pragma mark -- ***********************Necessary method**********************************************

/**
 初始化配置
 */
- (void)setupWithAppId:(NSString *)appId arId:(NSString *)arId;
- (void)registRecorder;

- (void)setupCamera;
- (void)destoryRecorder;
- (void)changeCameraToPhoto;
- (void)changeCameraToVideo;


/**
 在viewDidLayoutSubviews调用
 */
- (void)layoutPreview;

/**
 开启取景器 在viewDidAppear中
 */
- (void)startPreview;

/**
 关闭取景器 在ViewDidDisappear中
 */
- (void)stopPreview;

/**
 开始拍摄
 */
- (void)startCapture;

/**
 结束拍摄
 */
- (void)endCapture;


#pragma mark -- ***********************Setting method**********************************************

/**
 切换摄像头（前置，后置）
 */
- (void)switchCamera;

/**
 开启闪光灯
 @param isOn YES 开启。NO 关闭  默认关闭状态
 */
- (void)enableFlash:(BOOL)isOn;

/**
 回删所有拍摄的视频片段
 */
- (void)removeAllClips;
/**
 回删最后一次拍摄的视频片段
 */
- (void)removeLastVideoClip;

/**
 对焦
 @param point 焦点
 */
- (void)startFocus:(CGPoint)point;

#pragma mark -- ***********************get message method**********************************************

/**
 获取视频片段数
 */
- (NSInteger)getCaptureClipsCount;

/**
 获取录制视频的时长
 */
- (CGFloat)getCapturedDuration;

- (UIView *)getPreview;

/**
 是否正在录制
 @return YES。NO
 */
- (BOOL)getIsRecordingVideo;

/**
 获取当前拍摄图片
 */
- (void)getCaptureImage:(void(^ __nonnull)(UIImage *__nullable image))finish;

- (SenseArMaterial *_Nullable)getcrtMtr;
- (SenseArRenderStatus)useMaterial:(SenseArMaterial *_Nullable)material;

- (void)setPreviewHeight:(CGFloat)height;

- (void)capturePhoto:(void(^ __nonnull)(NSError *__nullable error, UIImage *__nullable image))completionHandler;

@end
